package com.builder;

import java.util.ArrayList;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;

import com.model.Stock;
import com.view.ClienteView;
import com.view.DepositoView;
import com.view.MovimientoStockView;
import com.view.StockView;

@SuppressWarnings("serial")
@ManagedBean
@ViewScoped
public class StockBuilder extends BaseBuilder<StockView, Stock> {

	@ManagedProperty("#{productoBuilder}")
	private ProductoBuilder productoBuilder;

	@ManagedProperty("#{proveedorBuilder}")
	private ProveedorBuilder proveedorBuilder;

	@ManagedProperty("#{movimientoStockBuilder}")
	private MovimientoStockBuilder movimientoStockBuilder;

	@ManagedProperty("#{depositoBuilder}")
	private DepositoBuilder depositoBuilder;

	@ManagedProperty("#{clienteBuilder}")
	private ClienteBuilder clienteBuilder;

	@Override
	public Stock toDomain(StockView view) {
		return new Stock(
				view.getId(),
				proveedorBuilder.toDomain(view.getProveedor()),
				productoBuilder.toDomain(view.getProducto()),
				view.getCantidad(),
				view.getFechaDeIngreso(),
				view.getFechaUltimoMovimiento(),
				view.getListaMovimientoStockView() != null ? movimientoStockBuilder
						.toDomain(view.getListaMovimientoStockView()) : null,
				view.getDeposito() != null
						&& view.getDeposito().getId() != null ? depositoBuilder
						.toDomain(view.getDeposito()) : null,
				view.getCliente() != null && view.getCliente().getId() != null ? clienteBuilder
						.toDomain(view.getCliente()) : null);
	}

	@Override
	public StockView toView(Stock model) {
		return new StockView(
				model.getID(),
				proveedorBuilder.toView(model.getProveedor()),
				productoBuilder.toView(model.getProducto()),
				model.getCantidad(),
				model.getFechaDeIngreso(),
				model.getFechaUltimoMovimiento(),
				model.getListaMovimientoStock() != null ? movimientoStockBuilder
						.toView(model.getListaMovimientoStock())
						: new ArrayList<MovimientoStockView>(),
				model.getDeposito() != null ? depositoBuilder.toView(model
						.getDeposito()) : new DepositoView(),
				model.getCliente() != null ? clienteBuilder.toView(model
						.getCliente()) : new ClienteView());
	}

	public ProductoBuilder getProductoBuilder() {
		return productoBuilder;
	}

	public void setProductoBuilder(ProductoBuilder productoBuilder) {
		this.productoBuilder = productoBuilder;
	}

	public ProveedorBuilder getProveedorBuilder() {
		return proveedorBuilder;
	}

	public void setProveedorBuilder(ProveedorBuilder proveedorBuilder) {
		this.proveedorBuilder = proveedorBuilder;
	}

	public MovimientoStockBuilder getMovimientoStockBuilder() {
		return movimientoStockBuilder;
	}

	public void setMovimientoStockBuilder(
			MovimientoStockBuilder movimientoStockBuilder) {
		this.movimientoStockBuilder = movimientoStockBuilder;
	}

	public DepositoBuilder getDepositoBuilder() {
		return depositoBuilder;
	}

	public void setDepositoBuilder(DepositoBuilder depositoBuilder) {
		this.depositoBuilder = depositoBuilder;
	}

	public ClienteBuilder getClienteBuilder() {
		return clienteBuilder;
	}

	public void setClienteBuilder(ClienteBuilder clienteBuilder) {
		this.clienteBuilder = clienteBuilder;
	}

}
